<?php
/**
 * Created by PhpStorm.
 * User: stupboy
 * Date: 2018/2/7
 * Time: 22:54
 */

namespace app\api\behavior;

/**
 * Class 司机操作通知乘客行为
 * @package app\api\behavior
 */
class Order
{
    public function __construct()
    {
        $this->push = new \app\base\logic\Push();
    }

    /**
     * 接单
     * @param $params
     */
    public function receOrder(&$params){
        $this->sendMsg($params);
    }

    /**
     * 开始订单
     * @param $params
     */
    public function startOrder(&$params){
        $this->sendMsg($params);
    }

    /**
     * 到达出发地
     * @param $params
     */
    public function arrivalOrder(&$params){
        $this->sendMsg($params);
    }

    /**
     * 开始订单
     * @param $params
     */
    public function goOrder(&$params){
        $this->sendMsg($params);
    }

    /**
     * 费用确认
     * @param $params
     */
    public function sureFee(&$params){
        $this->sendMsg($params);
    }

    public function sendMsg($oid=0){
        $order               = \app\api\model\Order::get($oid);
        if(empty($order)){
            return;
        }
        $data['order_id']    = $oid;
        $data['order_no']    = $order->order_no;
        $data['order_state'] = $order->order_state;
        $data['from_addr']   = $order->ordergps ? $order->ordergps->from_addr : '';
        $data['from_lon']    = $order->ordergps ? $order->ordergps->from_lon  : '';
        $data['from_lat']    = $order->ordergps ? $order->ordergps->from_lat  : '';
        $data['to_addr']     = $order->ordergps ? $order->ordergps->to_addr   : '';
        $data['to_lon']      = $order->ordergps ? $order->ordergps->to_lon    : '';
        $data['to_lat']      = $order->ordergps ? $order->ordergps->to_lat    : '';
        $sign                = $order->passenger->user->pushbind ? $order->passenger->user->pushbind->push_user_id : '';
        if(!empty($sign)){
            $msg             = json_encode($data);
            $this->push->pushPassenger([$sign],$msg);
        }
        //$this->push->pushDriver(['190e35f7e04fdbadc41','1a1018970aac146cb50'],$msg); //测试用
    }
}